package com.jeesite.common.utils.excel.fieldtype;

import java.util.List;

import org.springframework.core.NamedThreadLocal;

import com.jeesite.common.lang.StringUtils;
import com.jeesite.modules.edu.entity.EduSubject;
import com.jeesite.modules.sys.utils.EduUtils;

public class SubjectMajorType {
private static ThreadLocal<List<EduSubject>> cache = new NamedThreadLocal<>("EduSubjectType");
	
	/**
	 * 获取对象值（导入）
	 */
	public static Object getValue(String val) {
		List<EduSubject> cacheList = cache.get();
		if (cacheList == null){
			cacheList = EduUtils.getEduSubjectAllList();
			cache.set(cacheList);
		}
		for (EduSubject e : cacheList){
			if (StringUtils.trimToEmpty(val).equals(e.getDictLabel())){
				return e;
			}
		}
		return null;
	}

	/**
	 * 获取对象值（导出）
	 */
	public static String setValue(Object val) {
		
		if (val != null && ((EduSubject)val).getDictLabel() != null){
			//return ((EduSubject)val).getDictLabel();
			return ((EduSubject)val).getTreeNames();
		}
		return "";
	}

	
	/**
	 * 清理缓存
	 */
	public static void clearCache(){
		cache.remove();
	}
}
